/*
 * Course:    CS 590 Web Services
 * Semseter:  Spring 2009
 * Professor: Sedlemeyer
 * Project:   CHEAT (Code Help Educational Assignment Tool)
 * Due Date:  May 1, 2009
 * Team:      Sarcasm
 *            (Baker, Jason; Mitchell, Robin; Shie, Keith)
 */

package cheat.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 * Holds the licenses which may be/are associated with an assignment.
 *
 * @author Keith Shie
 */
@Entity
@Table(name = "license")
@NamedQueries({@NamedQuery(name = "License.findAll", query = "SELECT l FROM License l"),
        @NamedQuery(name = "License.findByLicenseId", query = "SELECT l FROM License l WHERE l.licenseId = :licenseId"),
        @NamedQuery(name = "License.findByDescr", query = "SELECT l FROM License l WHERE l.descr = :descr"),
        @NamedQuery(name = "License.findByUrl", query = "SELECT l FROM License l WHERE l.url = :url")})
public class License implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @Basic(optional = false)
  @SequenceGenerator(name="license_seq", sequenceName="license_license_id_seq", allocationSize=1)
  @GeneratedValue( strategy=GenerationType.SEQUENCE,generator="license_seq")
  @Column(name = "license_id", nullable = false)
  private Integer licenseId;
  @Basic(optional = false)
  @Lob
  @Column(name = "descr", nullable = false, length = 2147483647)
  private String descr;
  @Basic(optional = false)
  @Column(name = "url", nullable = false, length = 250)
  private String url;
  @OneToMany(cascade = CascadeType.ALL, mappedBy = "licenseId",fetch=FetchType.LAZY)
  private Collection<AssignmentProperty> asgnPropCollection;

  public License() {
  }

  public License(Integer licenseId) {
    this.licenseId = licenseId;
  }

  public License(Integer licenseId, String descr, String url) {
    this.licenseId = licenseId;
    this.descr = descr;
    this.url = url;
  }

  public Integer getLicenseId() {
    return licenseId;
  }

  public void setLicenseId(Integer licenseId) {
    this.licenseId = licenseId;
  }

  public String getDescr() {
    return descr;
  }

  public void setDescr(String descr) {
    this.descr = descr;
  }

  public String getUrl() {
    return url;
  }

  public void setUrl(String url) {
    this.url = url;
  }

  public Collection<AssignmentProperty> getAsgnPropCollection() {
    return asgnPropCollection;
  }

  public void setAsgnPropCollection(Collection<AssignmentProperty> asgnPropCollection) {
    this.asgnPropCollection = asgnPropCollection;
  }

  @Override
  public int hashCode() {
    int hash = 0;
    hash += (licenseId != null ? licenseId.hashCode() : 0);
    return hash;
  }

  @Override
  public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof License)) {
      return false;
    }
    License other = (License) object;
    if ((this.licenseId == null && other.licenseId != null) || (this.licenseId != null && !this.licenseId.equals(other.licenseId))) {
      return false;
    }
    return true;
  }

  @Override
  public String toString() {
    return "cheat.entities.License[licenseId=" + licenseId + "]";
  }

}
